System-specific parameters and functions



command line args

The list of command line arguments passed to a Python script.

argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string ‘-c’. If no script name was passed to the Python interpreter, argv[0] is the empty string.

echo 'import sys
for i in range(len(sys.argv)):
    print("sys.argv[" + str(i) + "] = \"" + sys.argv[i] + "\"")
' > 'temp.py'
python temp.py a b
#  sys.argv[0] = "temp.py"
#  sys.argv[1] = "a"
#  sys.argv[2] = "b"

path

import sys
from pprint import pprint
type(sys.path)
#  <class 'list'>
pprint(sys.path)
#  ['',
#   '/usr/local/anaconda3/envs/how2-py/bin',
#   '/usr/local/anaconda3/envs/how2-py/lib/python38.zip',
#   '/usr/local/anaconda3/envs/how2-py/lib/python3.8',
#   '/usr/local/anaconda3/envs/how2-py/lib/python3.8/lib-dynload',
#   '/usr/local/anaconda3/envs/how2-py/lib/python3.8/site-packages',
#   '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/reticulate/python']

E.g.

sys.path.append('extrapath') 
sys.path.extend(['extrapath'])
sys.path.insert(0, 'extrapath')

where extrapath is the path to a py file or a folder containing a py file?


python version

import sys
sys.version
#  '3.8.3 (default, Jul  2 2020, 11:30:46) \n[Clang 10.0.0 ]'
sys.prefix
#  '/usr/local/anaconda3/envs/how2-py'
sys.executable
#  '/usr/local/anaconda3/envs/how2-py/bin/python'

os

import sys
sys.platform
#  'darwin'

linux = Linux
win32 = Windows
cygwin = Windows/Cygwin
darwin = Mac OS X